from functools import wraps

from flask import redirect, session, url_for, g


def check_login(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        if hasattr(g, 'current_user') and g.current_user:
            return func(*args, **kwargs)
        return redirect(url_for('auth.login'))

    return wrapper
